﻿Friend Module General

#Region "Define System Variables"


    '=======================
    'Define System variables
    '=======================

    'Autobrew class

    Public Const SER_TIME As Integer = 0    'first item in tab delimited string
    Public Const SER_CLASS As Integer = 1     'second item in tab delimited string
    Public Const SER_MSG As Integer = 2
    Public Const TEMP_ID As Integer = 3
    Public Const TEMP_VAL As Integer = 4
    Public Const TEMP_UNIT As Integer = 5
    Public Const TS_ADDR_B0 As Integer = 4
    Public Const TS_ADDR_B1 As Integer = 5
    Public Const TS_ADDR_B2 As Integer = 6
    Public Const TS_ADDR_B3 As Integer = 7
    Public Const TS_ADDR_B4 As Integer = 8
    Public Const TS_ADDR_B5 As Integer = 9
    Public Const TS_ADDR_B6 As Integer = 10
    Public Const TS_ADDR_B7 As Integer = 11
    Public Const BOIL_TEMP As Integer = 3
    Public Const BOIL_UNIT As Integer = 4
    Public Const VALVE_BITS As Integer = 3
    Public Const VALVE_BITS2 As Integer = 4
    Public Const VALVE_PROFILE2 As Integer = 3
    Public Const ALM_STATUS As Integer = 3
    Public Const AUTO_VLV_STATUS As Integer = 3
    Public Const VER_NUM As Integer = 3
    Public Const BUILD_NUM As Integer = 4
    Public Const MENU_TITLE As Integer = 3
    Public Const MENU_OPTIONS As Integer = 4
    Public Const TUN_ID As Integer = 3
    Public Const CAPACITY As Integer = 4
    Public Const DEADSPACE As Integer = 5
    Public Const TUN_UNIT As Integer = 6
    Public Const DATA_VAL As Integer = 4
    Public Const VOL_ID As Integer = 3
    Public Const VOL_VAL As Integer = 4
    Public Const VOL_UNIT As Integer = 5
    Public Const STEP_ID As Integer = 3
    Public Const PROG_ID As Integer = 3
    Public Const TIME_LEFT As Integer = 3
    Public Const TIMER_ID2 As Integer = 3
    Public Const TIMER_STATUS As Integer = 4
    Public Const TIME_LEFT2 As Integer = 4
    Public Const TIMER_STATUS2 As Integer = 5
    Public Const VLV_PROFILE_MASK As Integer = 3
    Public Const VLV_FILLHLT As Integer = 3
    Public Const VLV_FILLMASH As Integer = 4
    Public Const VLV_ADDGRAIN As Integer = 5
    Public Const VLV_MASHHEAT As Integer = 6
    Public Const VLV_MASHIDLE As Integer = 7
    Public Const VLV_SPARGEIN As Integer = 8
    Public Const VLV_SPARGEOUT As Integer = 9
    Public Const VLV_HOPADD As Integer = 10
    Public Const VLV_KETTLELID As Integer = 11
    Public Const VLV_CHILLH20 As Integer = 12
    Public Const VLV_CHILLBEER As Integer = 13
    Public Const VLV_BOILRECIRC As Integer = 14
    Public Const VLV_DRAIN As Integer = 15
    Public Const SP_FILL As Integer = 3
    Public Const SP_DELAY As Integer = 4
    Public Const SP_PREHEAT As Integer = 5
    Public Const SP_GRAIN_IN As Integer = 6
    Public Const SP_REFILL As Integer = 7
    Public Const SP_DOUGH_IN As Integer = 8
    Public Const SP_ACID As Integer = 9
    Public Const SP_PROTEIN As Integer = 10
    Public Const SP_SACCH As Integer = 11
    Public Const SP_SACCH2 As Integer = 12
    Public Const SP_MASH_OUT As Integer = 13
    Public Const SP_MASH_HOLD As Integer = 14
    Public Const SP_SPARGE As Integer = 15
    Public Const SP_BOIL As Integer = 16
    Public Const SP_CHILL As Integer = 17
    Public Const OUTPUT_ID As Integer = 3
    Public Const OUTPUT_MODE As Integer = 4
    Public Const OUTPUT_CYCLE As Integer = 5
    Public Const OUTPUT_P_GAIN As Integer = 6
    Public Const OUTPUT_I_GAIN As Integer = 7
    Public Const OUTPUT_D_GAIN As Integer = 8
    Public Const OUTPUT_HYST As Integer = 9

    'BrewTroller ver 1.x program settings
    Public Const PS_PROG_NUM As Integer = 3
    Public Const PS_PROG_NAME As Integer = 4
    Public Const PS_DI_TEMP As Integer = 5
    Public Const PS_DI_MINS As Integer = 6
    Public Const PS_PROTEIN_TEMP As Integer = 7
    Public Const PS_PROTEIN_MINS As Integer = 8
    Public Const PS_SACCH_TEMP As Integer = 9
    Public Const PS_SACCH_MINS As Integer = 10
    Public Const PS_MO_TEMP As Integer = 11
    Public Const PS_MO_MINS As Integer = 12
    Public Const PS_SPARGE_TEMP As Integer = 13
    Public Const PS_DELAY_MINS As Integer = 14
    Public Const PS_HLT_SET As Integer = 15
    Public Const PS_BATCH_VOL As Integer = 16
    Public Const PS_GRAIN_WGT As Integer = 17
    Public Const PS_BOIL_MINS As Integer = 18
    Public Const PS_MASH_RATIO As Integer = 19
    Public Const PS_PITCH_TEMP As Integer = 20
    Public Const PS_BOIL_ADDNS As Integer = 21
    Public Const PS_GRAIN_TEMP As Integer = 22
    'BrewTroller ver 2.x program settings
    Public Const PS2_PROG_NUM As Integer = 3
    Public Const PS2_PROG_NAME As Integer = 4
    Public Const PS2_DI_TEMP As Integer = 5
    Public Const PS2_DI_MINS As Integer = 6
    Public Const PS2_ACID_TEMP As Integer = 7
    Public Const PS2_ACID_MINS As Integer = 8
    Public Const PS2_PROTEIN_TEMP As Integer = 9
    Public Const PS2_PROTEIN_MINS As Integer = 10
    Public Const PS2_SACCH_TEMP As Integer = 11
    Public Const PS2_SACCH_MINS As Integer = 12
    Public Const PS2_SACCH2_TEMP As Integer = 13
    Public Const PS2_SACCH2_MINS As Integer = 14
    Public Const PS2_MO_TEMP As Integer = 15
    Public Const PS2_MO_MINS As Integer = 16
    Public Const PS2_SPARGE_TEMP As Integer = 17
    Public Const PS2_HLT_SET As Integer = 18
    Public Const PS2_BATCH_VOL As Integer = 19
    Public Const PS2_GRAIN_WGT As Integer = 20
    Public Const PS2_BOIL_MINS As Integer = 21
    Public Const PS2_MASH_RATIO As Integer = 22
    Public Const PS2_PITCH_TEMP As Integer = 23
    Public Const PS2_BOIL_ADDNS As Integer = 24
    Public Const PS2_PROG_UNIT As Integer = 25

    Public ABstep(2) As String 'step information
    Public Const ABSTEP_NUM As Integer = 1

    Public ABstart As String    'time in millis of start

    Public ABsettings(30) As String  'system settings from autobrew
    Public Const ABS_DOUGH_IN_TEMP As Integer = 1   'parameter set for ABsettings
    Public Const ABS_DOUGH_IN_MINS As Integer = 2   'parameter set for ABsettings
    Public Const ABS_PROTEIN_TEMP As Integer = 3   'parameter set for ABsettings
    Public Const ABS_PROTEIN_MINS As Integer = 4   'parameter set for ABsettings
    Public Const ABS_SACC_TEMP As Integer = 5   'parameter set for ABsettings
    Public Const ABS_SACC_MINS As Integer = 6   'parameter set for ABsettings
    Public Const ABS_MASH_OUT_TEMP As Integer = 7   'parameter set for ABsettings
    Public Const ABS_MASH_OUT_MINS As Integer = 8   'parameter set for ABsettings
    Public Const ABS_SPARGE_TEMP As Integer = 9   'parameter set for ABsettings
    Public Const ABS_DELAY_MINS As Integer = 10   'parameter set for ABsettings
    Public Const ABS_HLT_TARG_VOL As Integer = 11   'parameter set for ABsettings
    Public Const ABS_MASH_TARG_VOL As Integer = 12   'parameter set for ABsettings
    Public Const ABS_KET_TARG_VOL As Integer = 13   'parameter set for ABsettings
    Public Const ABS_GRAIN_WEIGHT As Integer = 14   'parameter set for ABsettings
    Public Const ABS_BOIL_MINS As Integer = 15   'parameter set for ABsettings
    Public Const ABS_MASH_RATIO As Integer = 16   'parameter set for ABsettings
    Public Const ABS_PITCH_TEMP As Integer = 17   'parameter set for ABsettings
    Public Const ABS_BOIL_ADDITIONS As Integer = 18   'parameter set for ABsettings
    Public Const ABS_GRAIN_TEMP As Integer = 19   'parameter set for ABsettings
    Public blnLoadBTrecipe As Boolean = False
    Public intLoadBTrecipeNum As Integer = 99

    'Data class

    'Array position (0, x) - time value
    'Array position (1, x) - state of alarm
    'publicension x represents record number of alarm state recorded 
    Public Dat_Alm(2, 500) As String
    Public Const DAT_ALM_STATE = 1
    Public Dat_Alm_Ptr As Integer  'points to current record

    'Array position (0, x) - time value
    'Array position (1, x) - state of valves (32 bits)
    'publicension x represents record number of valve state recorded 
    Public Dat_Vlv(2, 5000) As String
    Public Const DAT_VLV_STATE = 1
    Public Dat_Vlv_Ptr As Integer  'points to current record

    'Array position (0, x) - time value
    'Array position (1, x) - temperature value
    'publicension x represents record number of temperature recorded 
    Public Dat_Temp_HLT(2, 5000) As String
    Public Const DAT_TEMP_VAL = 1

    'Array position (0, x) - time value
    'Array position (1, x) - temperature value
    'publicension x represents record number of temperature recorded 
    Public Dat_Temp_Unit As Integer '0=Celcius, 1=Fahrenheit
    Public Dat_Temp_HLT_Ptr As Integer  'points to current record

    'Array position (0, x) - time value
    'Array position (1, x) - temperature value
    'publicension x represents record number of temperature recorded 
    Public Dat_Temp_MASH(2, 5000) As String

    'Array position (0, x) - time value
    'Array position (1, x) - temperature value
    'publicension x represents record number of temperature recorded 
    Public Dat_Temp_KET(2, 5000) As String

    'Array position (0, x) - time value
    'Array position (1, x) - level value
    'publicension x represents record number of temperature recorded 
    Public Dat_Level_HLT(2, 5000) As String
    Public Const DAT_LEVEL_VAL = 1

    Public Dat_Level_Unit As Integer   '0=Litres, 1=Gallons

    'Array position (0, x) - time value
    'Array position (1, x) - level value
    'publicension x represents record number of temperature recorded 
    Public Dat_Level_MASH(3, 5000) As String

    'Array position (0, x) - time value
    'Array position (1, x) - level value
    'publicension x represents record number of temperature recorded 
    Public Dat_Level_KET(3, 5000) As String

    'Debug class
    Public Vol_Calib_HLT(30) As String       'dump of calibration values and volumes
    Public Vol_Calib_Mash(30) As String      'dump of calibration values and volumes
    Public Vol_Calib_Kettle(30) As String    'dump of calibration values and volumes
    Public Const VC_VESSEL As Integer = 1           'parameter set for vol_calib
    Public Const VC_VOL1 As Integer = 2   'parameter set for vol_calib
    Public Const VC_VAL1 As Integer = 3   'parameter set for vol_calib
    Public Const VC_VOL2 As Integer = 4   'parameter set for vol_calib
    Public Const VC_VAL2 As Integer = 5   'parameter set for vol_calib
    Public Const VC_VOL3 As Integer = 6   'parameter set for vol_calib
    Public Const VC_VAL3 As Integer = 7   'parameter set for vol_calib
    Public Const VC_VOL4 As Integer = 8   'parameter set for vol_calib
    Public Const VC_VAL4 As Integer = 9   'parameter set for vol_calib
    Public Const VC_VOL5 As Integer = 10   'parameter set for vol_calib
    Public Const VC_VAL5 As Integer = 11   'parameter set for vol_calib
    Public Const VC_VOL6 As Integer = 12   'parameter set for vol_calib
    Public Const VC_VAL6 As Integer = 13   'parameter set for vol_calib
    Public Const VC_VOL7 As Integer = 14   'parameter set for vol_calib
    Public Const VC_VAL7 As Integer = 15   'parameter set for vol_calib
    Public Const VC_VOL8 As Integer = 16   'parameter set for vol_calib
    Public Const VC_VAL8 As Integer = 17   'parameter set for vol_calib
    Public Const VC_VOL9 As Integer = 18   'parameter set for vol_calib
    Public Const VC_VAL9 As Integer = 19   'parameter set for vol_calib
    Public Const VC_VOL10 As Integer = 20   'parameter set for vol_calib
    Public Const VC_VAL10 As Integer = 21   'parameter set for vol_calib

    Public Vol_Read_HLT(10) As String
    Public Vol_Read_Mash(10) As String
    Public Vol_Read_Kettle(10) As String
    Public Const VR_VESSEL As Integer = 1           'parameter set for vol_read
    Public Const VR_RAW As Integer = 2   'parameter set for vol_read
    Public Const VR_ZERO As Integer = 3   'parameter set for vol_read
    Public Const VR_CORRECTED As Integer = 4   'parameter set for vol_read
    Public Const VR_UPPER_CAL As Integer = 5   'parameter set for vol_read
    Public Const VR_LOWER_CAL As Integer = 6   'parameter set for vol_read
    Public Const VR_2_LOWER_CAL As Integer = 7   'parameter set for vol_read
    Public Const VR_RETURN As Integer = 8   'parameter set for vol_read

    'Menu Class
    Public Menu_Prompt(10) As String
    Public Const MP_TITLE As Integer = 1           'parameter set for menu_prompt
    Public Const MP_NUM_OPTS As Integer = 2   'parameter set for menu_prompt
    Public Const MP_OPT0 As Integer = 3   'parameter set for menu_prompt
    Public Const MP_OPT1 As Integer = 4   'parameter set for menu_prompt
    Public Const MP_OPT2 As Integer = 5   'parameter set for menu_prompt
    Public Const MP_OPT3 As Integer = 6   'parameter set for menu_prompt
    Public Const MP_OPT4 As Integer = 7   'parameter set for menu_prompt
    Public Const MP_OPT5 As Integer = 8   'parameter set for menu_prompt
    Public Const MP_OPT6 As Integer = 9   'parameter set for menu_prompt
    Public Const MP_OPT7 As Integer = 10   'parameter set for menu_prompt

    Public Menu_Result(10) As String
    Public Const MR_TITLE As Integer = 1           'parameter set for menu_result
    Public Const MR_OPTION As Integer = 2   'parameter set for menu_result
    Public Const MR_OPTION_TITLE As Integer = 3   'parameter set for menu_result

    Public Menu_Select As String

    'System Class
    Public Sys_Config(2) As String
    Public Const SYSC_VER As Integer = 1

    Public Sys_Version(2) As String
    Public Const SYSV_VER As Integer = 1

    Public Sys_PLR As String

    Public ptrLines As Long    'points to serial line number that was last processed

    Public oFile As System.IO.File
    Public oRead As System.IO.StreamReader
    Public strXMLdata As String
    Public blnDoFTPupload As Boolean = False
    Public blnAllowVPchanges As Boolean = True
    Public intVlvStep As Integer = 0  'active valve profile number

#End Region

#Region "Define display variables"

    'for adding/subtracting time to the timer
    Public lngTimeDisplayed As Long

    'for setting vessel temp setpoints
    Public intHLTSetTemp As Integer
    Public intMLTSetTemp As Integer
    Public intBoilSetTemp As Integer
    Public intPrimActiveValveProfile As Integer

    Friend DisplayInfo(200) As String
    Public DataInfo(200) As String
    Public TestValve(34) As Integer

    Public Const DI_ALARM_STATUS As Integer = 0
    Public Const DI_VLV_STATUS As Integer = 1
    Public Const DI_VLV1 As Integer = 3
    Public Const DI_VLV2 As Integer = 4
    Public Const DI_VLV3 As Integer = 5
    Public Const DI_VLV4 As Integer = 6
    Public Const DI_VLV5 As Integer = 7
    Public Const DI_VLV6 As Integer = 8
    Public Const DI_VLV7 As Integer = 9
    Public Const DI_VLV8 As Integer = 10
    Public Const DI_VLV9 As Integer = 11
    Public Const DI_VLV10 As Integer = 12
    Public Const DI_VLV11 As Integer = 13
    Public Const DI_VLV12 As Integer = 14
    Public Const DI_VLV13 As Integer = 15
    Public Const DI_VLV14 As Integer = 16
    Public Const DI_VLV15 As Integer = 17
    Public Const DI_VLV16 As Integer = 18
    Public Const DI_VLV17 As Integer = 19
    Public Const DI_VLV18 As Integer = 20
    Public Const DI_VLV19 As Integer = 21
    Public Const DI_VLV20 As Integer = 22
    Public Const DI_VLV21 As Integer = 23
    Public Const DI_VLV22 As Integer = 24
    Public Const DI_VLV23 As Integer = 25
    Public Const DI_VLV24 As Integer = 26
    Public Const DI_VLV25 As Integer = 27
    Public Const DI_VLV26 As Integer = 28
    Public Const DI_VLV27 As Integer = 29
    Public Const DI_VLV28 As Integer = 30
    Public Const DI_VLV29 As Integer = 31
    Public Const DI_VLV30 As Integer = 32
    Public Const DI_VLV31 As Integer = 33
    Public Const DI_VLV32 As Integer = 34
    Public Const DI_HLT_TEMP As Integer = 35
    Public Const DI_MASH_TEMP As Integer = 36
    Public Const DI_KET_TEMP As Integer = 37
    Public Const DI_TEMP_H2O_IN As Integer = 38
    Public Const DI_TEMP_H2O_OUT As Integer = 39
    Public Const DI_TEMP_BEER As Integer = 40
    Public Const DI_HLT_VOL As Integer = 41
    Public Const DI_MASH_VOL As Integer = 42
    Public Const DI_KET_VOL As Integer = 43
    Public Const DI_STEP_DESCR As Integer = 44
    Public Const DI_AUTO_VLV_DESCR As Integer = 45
    Public Const DI_HLT_HEAT As Integer = 46
    Public Const DI_MASH_HEAT As Integer = 47
    Public Const DI_KET_HEAT As Integer = 48
    Public Const DI_STEAM_HEAT As Integer = 49
    Public Const DI_HLT_SET As Integer = 50
    Public Const DI_MASH_SET As Integer = 51
    Public Const DI_KET_SET As Integer = 52
    Public Const DI_PGM_ID As Integer = 53
    Public Const DI_TIME_VAL As Integer = 54
    Public Const DI_TIME_STATUS As Integer = 55
    Public Const DI_VLV_PROF As Integer = 56
    Public Const DI_TEMP_AUX1 As Integer = 57
    Public Const DI_TEMP_AUX2 As Integer = 58
    Public Const DI_TEMP_AUX3 As Integer = 59
    Public Const DI_RAW_HLT As Integer = 60
    Public Const DI_RAW_MASH As Integer = 61
    Public Const DI_RAW_KET As Integer = 62
    Public Const DI_ABSTEP_NUM As Integer = 63
    Public Const DI_TIME_MILLIS As Integer = 64
    Public Const DI_RUNNING_PROGRAMS As Integer = 65
    Public Const DI_TIME_VAL2 As Integer = 66
    Public Const DI_TIME_STATUS2 As Integer = 67
    Public Const DI_VER As Integer = 68
    Public Const DI_BUILD As Integer = 69
    Public Const DI_BOIL_TEMP As Integer = 70
    Public Const DI_HLT_CAPACITY = 71
    Public Const DI_HLT_DS As Integer = 72
    Public Const DI_HLT_UNIT As Integer = 73
    Public Const DI_MASH_CAPACITY = 74
    Public Const DI_MASH_DS As Integer = 75
    Public Const DI_MASH_UNIT As Integer = 76
    Public Const DI_KET_CAPACITY As Integer = 77
    Public Const DI_KET_DS As Integer = 78
    Public Const DI_KET_UNIT As Integer = 79
    Public Const DI_TS_HLT As Integer = 80
    Public Const DI_TS_MASH As Integer = 81
    Public Const DI_TS_KET As Integer = 82
    Public Const DI_TS_H2OIN As Integer = 83
    Public Const DI_TS_H2OOUT As Integer = 84
    Public Const DI_TS_BEEROUT As Integer = 85
    Public Const DI_TS_AUX1 As Integer = 86
    Public Const DI_TS_AUX2 As Integer = 87
    Public Const DI_TS_AUX3 As Integer = 88
    Public Const DI_HLT_OP_MODE As Integer = 89
    Public Const DI_HLT_OP_CYCLE As Integer = 90
    Public Const DI_HLT_OP_P As Integer = 91
    Public Const DI_HLT_OP_I As Integer = 92
    Public Const DI_HLT_OP_D As Integer = 93
    Public Const DI_HLT_OP_HYST As Integer = 94
    Public Const DI_MASH_OP_MODE As Integer = 95
    Public Const DI_MASH_OP_CYCLE As Integer = 96
    Public Const DI_MASH_OP_P As Integer = 97
    Public Const DI_MASH_OP_I As Integer = 98
    Public Const DI_MASH_OP_D As Integer = 99
    Public Const DI_MASH_OP_HYST As Integer = 100
    Public Const DI_KETTLE_OP_MODE As Integer = 101
    Public Const DI_KETTLE_OP_CYCLE As Integer = 102
    Public Const DI_KETTLE_OP_P As Integer = 103
    Public Const DI_KETTLE_OP_I As Integer = 104
    Public Const DI_KETTLE_OP_D As Integer = 105
    Public Const DI_KETTLE_OP_HYST As Integer = 106
    Public Const DI_STEAM_OP_MODE As Integer = 107
    Public Const DI_STEAM_OP_CYCLE As Integer = 108
    Public Const DI_STEAM_OP_P As Integer = 109
    Public Const DI_STEAM_OP_I As Integer = 110
    Public Const DI_STEAM_OP_D As Integer = 111
    Public Const DI_STEAM_OP_HYST As Integer = 112

    'Serial message stack
    Public strSerialMsg(100) As String

    Public blnAssignTS_SCAN_to_0 As Boolean = False
    Public blnAssignTS_SCAN_to_1 As Boolean = False
    Public blnAssignTS_SCAN_to_2 As Boolean = False
    Public blnAssignTS_SCAN_to_3 As Boolean = False
    Public blnAssignTS_SCAN_to_4 As Boolean = False
    Public blnAssignTS_SCAN_to_5 As Boolean = False
    Public blnAssignTS_SCAN_to_6 As Boolean = False
    Public blnAssignTS_SCAN_to_7 As Boolean = False
    Public blnAssignTS_SCAN_to_8 As Boolean = False

    Public strBTrecipeNames(29) As String

    Public TimeStamp(30) As Long
    Public Const TS_AB_START_TIME As Integer = 0 'time stamp of autobrew start (millis)
    Public Const TS_VLV_STATUS As Integer = 1 'time stamp of valve status information

#End Region

#Region "Bit wise functions & procedures"

    'bit wise functions
    ' The ClearBit Sub clears the 1 based, nth bit 
    ' (MyBit) of an integer (MyByte).
    Sub ClearBit(ByRef MyByte, ByVal MyBit)
        Dim BitMask As Int32
        ' Create a bitmask with the 2 to the nth power bit set:
        BitMask = 2 ^ (MyBit - 1)
        ' Clear the nth Bit:
        MyByte = MyByte And Not BitMask
    End Sub

    ' The ExamineBit function will return True or False 
    ' depending on the value of the 1 based, nth bit (MyBit) 
    ' of an integer (MyByte).
    Function ExamineBit(ByVal MyByte, ByVal MyBit) As Boolean
        Dim BitMask As Int64
        BitMask = 2 ^ (MyBit - 1)
        ExamineBit = ((MyByte And BitMask) > 0)
    End Function

    ' The SetBit Sub will set the 1 based, nth bit 
    ' (MyBit) of an integer (MyByte).
    Sub SetBit(ByRef MyByte, ByVal MyBit)
        Dim BitMask As Int32
        BitMask = 2 ^ (MyBit - 1)
        MyByte = MyByte Or BitMask
    End Sub

    ' The ToggleBit Sub will change the state 
    ' of the 1 based, nth bit (MyBit)
    ' of an integer (MyByte).
    Sub ToggleBit(ByRef MyByte, ByVal MyBit)
        Dim BitMask As Int32
        BitMask = 2 ^ (MyBit - 1)
        MyByte = MyByte Xor BitMask
    End Sub

#End Region

    Public Sub AddToTXstack(ByVal strCommand As String)

        'find the first stack value with 'nothing' in it
        For i = 0 To 100
            If strSerialMsg(i) = Nothing Then
                'add command here
                strSerialMsg(i) = strCommand
                'and exit for
                Exit For
            End If
        Next

    End Sub


End Module
